<template>
  <el-dialog
    class="met-dialog"
    title="客户选择"
    width="950px"
    :visible.sync="dialog.visible"
    :append-to-body="true"
  >
    <!-- 添加 会议室-->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      class="header"
    >
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          class="w150"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编号" prop="customerNo">
        <el-input
          v-model="queryParams.customerNo"
          placeholder="请输入客户编号"
          clearable
          class="w150"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="客户状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择"
          class="w150"
        >
          <el-option
            v-for="item in dict.type.customer_state"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="roleList"
      highlight-current-row
      @current-change="handleCurrentChange"
      height="500"
    >
      <el-table-column label="客户编号" prop="customerNo" />
      <el-table-column
        label="客户名称"
        prop="customerName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="身份证号码"
        prop="idCard"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="客户分类"
        prop="roleKey"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type[scope.row.categoryId]"
            :value="scope.row.subCategoryId"
          />
        </template>
      </el-table-column>
      <el-table-column label="客户状态" prop="state">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.customer_state"
            :value="scope.row.state"
          />
        </template>
      </el-table-column>
      <el-table-column label="登记分所" prop="serviceGroupName" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div class="foot">
      <el-button type="primary" @click="submitForm('queryForm')"
        >确定</el-button
      >
      <el-button @click="resetForm('queryForm')">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listRole, delRole } from "@/api/system/role";
import { customerlist } from "@/api/case/case";
export default {
  components: {},
  dicts: ["customer_state", "approval_status", "category_id", "unit", "person"],
  data() {
    return {
      dialog: {
        visible: false,
        title: "客户选择",
      },
      options: [{ value: 1, label: "正常" }],
      roleList: [], //表格数组
      total: 1,
      loading: false,
      current: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
      },
    };
  },
  computed: {},
  methods: {
    //打开弹窗
    async open() {
      this.getList();
      this.current = null;
      this.dialog.visible = true;
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      customerlist(this.queryParams).then((response) => {
        this.roleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.roleList = [];
      this.$refs["queryForm"].resetFields();
      this.handleQuery();
    },
    // //选择客户
    // handleSelectionChange(val) {
    //   console.log(val);
    //   this.current = val;
    // },
    handleCurrentChange(val) {
      console.log(val);
      this.current = val;
    },
    submitForm(formName) {
      if (this.current) {
        this.resetForm("queryForm");
        console.log("提交成功");
        this.$emit("submit", this.current);
      } else {
        this.$message.warning("请先选择数据！");
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialog.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.foot {
  text-align: center;
  margin-top: 50px;
}
.header {
  margin: 20px;
}
::v-deep .w150.el-input.el-input--small.el-input--suffix {
  width: 150px;
}
::v-deep .el-select.w150.el-select--small {
  width: 150px;
}
::v-deep .pagination-container .el-pagination {
  position: relative;
  left: 0;
  right: 0;
  text-align: center;
}
::v-deep .el-dialog__body {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  padding: 20px;
}
::v-deep .el-table__body-wrapper.is-scrolling-none {
  min-height: 130px !important;
  height: calc(100vh - 570px) !important;
}
</style>
